package org.atlantis.ymer.common;

import java.security.SecureRandom;
import java.util.Random;

public final class IdGenerator {

	private static final char[] BASE64_ALPHABET = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_"
			.toCharArray();
	private static final int ID_LENGTH = 20;
	private static Random random = new SecureRandom();

	public static String generate() {
		StringBuilder id = new StringBuilder();
		byte[] bytes = new byte[ID_LENGTH];
		random.nextBytes(bytes);
		for (int i = 0; i < bytes.length; i++) {
			id.append(BASE64_ALPHABET[bytes[i] & 0X3F]);
		}
		return id.toString();
	}
}
